#include "Rational.h"


	Rational & Rational::operator = (const Rational& val) {
		if(this == &val) {
			return *this;
		}
		num = val.num;
		den = val.den;
		return *this;
	}

	Rational  & Rational::operator+=(const Rational& val) {
		num = num*val.den + val.num*den;
		den = den * val.den;
		normalize();
		return *this;
	}

	Rational  & Rational::operator-=(const Rational& val) {
		num = num*val.den - val.num*den;
		den = den * val.den;
		normalize();
		return *this;
	}

	Rational  & Rational::operator*=(const Rational& val) {
		num = num * val.num;
		den = den * val.den;
		normalize();
		return *this;
	}

	Rational  & Rational::operator/=(const Rational& val) {
		num = num * val.den;
		den = den * val.num;
		normalize();
		return *this;
	}

	Rational  & Rational::operator++() {
		num += den;
		return *this;
	}

	Rational Rational::operator++(int) {
		Rational temp(*this);
		++(*this);
		return temp;
	}

	Rational & Rational::operator--() {
		num -= den;
		return *this;
	}

	Rational Rational::operator--(int) {
		Rational temp(*this);
		--(*this);
		return temp;
	}


	Rational::operator double() {
		return (double)num/den;
	}


	Rational operator+ (const Rational& a, const Rational& b){
		Rational temp(a);
		temp += b;
		return temp;
	}

	Rational operator- (const Rational& a, const Rational& b) {
		Rational temp(a);
		temp -= b;
		return temp;
	}

	Rational operator* (const Rational& a, const Rational& b) {
		Rational temp(a);
		temp *= b;
		return temp;
	}

	Rational operator/ (const Rational& a, const Rational& b) {
		Rational temp(a);
		temp /= b;
		return temp;
	}

	
	bool operator== (const Rational& a, const Rational& b) {
		return a.num == b.num && a.den == b.den ;
	}

	bool operator!= (const Rational& a, const Rational& b) {
		return !(a==b);
	}
	
	bool operator<= (const Rational& a, const Rational& b) {
		Rational temp = a-b;
		return temp.num <= 0;
	}

	bool operator>= (const Rational& a, const Rational& b) {
		Rational temp = a-b;
		return temp.num >= 0;
	}

	bool operator<  (const Rational& a, const Rational& b) {
		Rational temp = a-b;
		return temp.num < 0;
	}

	bool operator>  (const Rational& a, const Rational& b) {
		Rational temp = a-b;
		return temp.num > 0;
	}

	ostream &operator<<(ostream &out, const Rational & a){
		cout << a.num << "/" << a.den;
		return out;
	}